#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,r,cnt,a[20],v[20];
string s[100010],s1;
void dfs(int x)
{
	if(x > n)
	{
		int sum = a[1];
		for(int i = 2;i <= n;i++)
		{
			if(sum <= a[i]) return;
			sum += a[i];
		}
		cnt++;
		for(int i = 1;i <= n;i++) s[cnt] += (a[i]+'0');
		return;
	}
	for(int i = 1;i <= n;i++) if(!v[i]) v[i] = 1,a[x] = i,dfs(x+1),v[i] = 0;
}
signed main()
{
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	scanf("%lld%lld",&n,&r);
	if(n <= 8)
	{
		dfs(1);
		sort(s+1,s+1+cnt);
		for(int i = 0;i < n;i++) cout<<s[r][i]<<" ";
		return 0;
	} 
	if(r == 1)
	{
		cout<<"3 1 2 ";
		for(int i = 4;i <= n;i++) cout<<i<<" ";
	}
		cout<<"3 1 4 2 ";
		for(int i = 5;i <= n;i++) cout<<i<<" ";
	return 0;
}


